package com.doujiang.tools;

import java.util.HashMap;

public class jhjAjaxResult extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    /** 状态码（成功） */
    public static final int SUCCESS = 200;

    /** 状态码（失败） */
    public static final int FAIL = 500;

    public jhjAjaxResult() {}

    public jhjAjaxResult(int code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public jhjAjaxResult(int code, String msg, Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        if (data != null) {
            super.put(DATA_TAG, data);
        }
    }

    public static jhjAjaxResult success() {
        return new jhjAjaxResult(SUCCESS, "操作成功");
    }

    public static jhjAjaxResult success(Object data) {
        return new jhjAjaxResult(SUCCESS, "操作成功", data);
    }

    public static jhjAjaxResult success(String msg, Object data) {
        return new jhjAjaxResult(SUCCESS, msg, data);
    }

    public static jhjAjaxResult error() {
        return new jhjAjaxResult(FAIL, "操作失败");
    }

    public static jhjAjaxResult error(String msg) {
        return new jhjAjaxResult(FAIL, msg);
    }

    public static jhjAjaxResult error(String msg, Object data) {
        return new jhjAjaxResult(FAIL, msg, data);
    }
}
